﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using agsXMPP;
using JabberBotCore;

namespace CommonGame.Commands
{
    class Register : CommandBase
    {
        private readonly string owner;
        private readonly string msg;
        private readonly JabberProtocol jProt;

        public Register(string owner, string msg, JabberProtocol jProt) : base(owner, msg, jProt)
        {
            this.owner = owner;
            this.msg = msg;
            this.jProt = jProt;
        }

        public override void Execute()
        {
            String pPath = helper.paths.getPlayersDataPath();
            String[] strings = msg.Split(' ');
            var name = strings[0];

            if (name == "")
                jProt.msgSend(new Jid(owner), "ERR_EMPTY_PLAYER_NAME");
            if (Directory.Exists(pPath + "\\" + name))
                jProt.msgSend(new Jid(owner), "This player name is already exists");
            var _pm = new PManager();
            _pm.LoadPlayers();
            _pm.CreatePlayer(name, owner);
                jProt.msgSend(new Jid(owner), string.Format("Your Player with name - {0}successfully created", name));
        }
    }
}
